﻿using System.Reflection;
using FarmSmartSleep.Common.Domain.RBACFile;
using MediatR;
using SheepCultivation.API.AddliCation.SheepFarmsetup;
using SheepCultivation.Common.Domain;
using SheepCultivation.Common.Domain.SheepFarmSetting;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;

namespace SheepCultivation.API.AddliCation.RBAC
{
    public class EmployeeCreateHandler : IRequestHandler<EmployeeCreateCommon, Result>
    {
        public readonly IBaseRepository<Employee> EmployeeRepository;
        public EmployeeCreateHandler(IBaseRepository<Employee> employeeRepository)
        {
            EmployeeRepository = employeeRepository;
        }

        public async Task<Result> Handle(EmployeeCreateCommon request, CancellationToken cancellationToken)
        {
            var res= new Result() { Code = (int)CommonEnumCode.error };
            try
            {
                var result = new Employee()
                {
                    FirstName=request.FirstName,
                    Gender=request.Gender,
                    IdType=request.IdType,
                    IdNumber=request.IdNumber,
                    PhoneNumber = request.PhoneNumber,
                    Email = request.Email,
                    University = request.University,
                    EducationLevel = request.EducationLevel,
                    Company = request.Company,
                    EmploymentStatus = request.EmploymentStatus,
                    Department = request.Department,
                    EntryDate=request.EntryDate,
                    ProbationDate = request.ProbationDate,
                    JobTitle= request.JobTitle,
                    Position= request.Position,
                    HrLevel= request.HrLevel,
                    Account= request.Account,
                    Password= request.Password,
                };
                EmployeeRepository.Add(result);
                res.Code = (int)CommonEnumCode.success;
                res.Msg = "员工新增";
            }
            catch (Exception)
            {

                throw;
            }

            return res;
        }
    }
}
